//
//  VipCardInfoView.m
//  fitnessmanage
//
//  Created by 众拳科技 on 2017/11/1.
//  Copyright © 2017年 zongquankeji. All rights reserved.
//

#import "VipCardInfoView.h"
#import "UIButton+Mybutton.h"

@implementation VipCardInfoView

-(id)initWithFrame:(CGRect)frame{
    
    self = [super initWithFrame:frame];
    
    if (self) {
        
        self.bgNameArray = [NSMutableArray arrayWithObjects:@"carddetail_card_black",@"carddetail_card_white",@"carddetail_card_yellow", nil];
        
        self.backgroundColor = CSWhiteColor;
        
        
        UIImageView *backgroundImageView = [[UIImageView alloc] init];
        backgroundImageView.image = [UIImage imageNamed:@"carddetail_card_bg"];
        [self addSubview:backgroundImageView];
        self.backgroundImageView = backgroundImageView;
        
        /**
         卡面背景
         */
        UIImageView *bgView = [[UIImageView alloc] init];
        bgView.layer.cornerRadius = 4;
        bgView.layer.masksToBounds = YES;
        [self addSubview:bgView];
        self.bgView = bgView;
        
        /**
         卡名称
         */
        UILabel *cardNameLabel = [[UILabel alloc] init];
        cardNameLabel.font = [UIFont boldSystemFontOfSize:20];
        cardNameLabel.text = @"健身年卡";
        cardNameLabel.textColor = CSColorFromRGB(0xffffff);
        [bgView addSubview:cardNameLabel];
        self.cardNameLabel = cardNameLabel;
        
        /**
         线条
         */
        UIView *lineView = [[UIView alloc] init];
        lineView.backgroundColor = CSColorFromRGB(0x403f4a);
        [bgView addSubview:lineView];
        self.lineView = lineView;
        
        /**
         会员卡ID
         */
        UILabel *cardIdLabel = [[UILabel alloc] init];
        cardIdLabel.font = [UIFont systemFontOfSize:13.0];
        cardIdLabel.text = @"ID:10022";
        cardIdLabel.textColor = CSColorFromRGB(0x686578);
        [bgView addSubview:cardIdLabel];
        self.cardIdLabel = cardIdLabel;
        
        
        /**
         y有效期
         */
        TTTAttributedLabel *validLabel = [[TTTAttributedLabel alloc] initWithFrame:CGRectZero];
        validLabel.font = [UIFont systemFontOfSize:13.0];
        validLabel.textColor = CSColorFromRGB(0x686578);
        validLabel.lineBreakMode = NSLineBreakByCharWrapping;
        validLabel.numberOfLines = 0;
        validLabel.lineSpacing = 5;
        validLabel.text = @"有效期";
        [bgView addSubview:validLabel];
        self.validLabel = validLabel;
        
        /**
         时间
         */
        TTTAttributedLabel *validTimeLabel = [[TTTAttributedLabel alloc] initWithFrame:CGRectZero];
        validTimeLabel.font = [UIFont systemFontOfSize:15.0];
        validTimeLabel.textColor = CSColorFromRGB(0xffffff);
        validTimeLabel.lineBreakMode = NSLineBreakByCharWrapping;
        validTimeLabel.numberOfLines = 0;
        validTimeLabel.lineSpacing = 5;
        validTimeLabel.text = @"2017.10.21-2018.10.21";
        [bgView addSubview:validTimeLabel];
        self.validTimeLabel = validTimeLabel;;
        
        
        /**
         价格
         */
        UILabel *priceLabel = [[UILabel alloc] init];
        priceLabel.font = MidBigFont;
        priceLabel.text = @"200";
        priceLabel.font = [UIFont boldSystemFontOfSize:25.0];
        priceLabel.textColor = CSColorFromRGB(0xffffff);
        [bgView addSubview:priceLabel];
        self.priceLabel = priceLabel;
        
        /**
         元
         */
        UILabel *priceUnitLabel = [[UILabel alloc] init];
        priceUnitLabel.text = @"元";
        priceUnitLabel.textColor = CSWhiteColor;
        priceUnitLabel.font = SmallFont;
        priceUnitLabel.textColor = CSColorFromRGB(0xffffff);
        [bgView addSubview:priceUnitLabel];
        self.priceUnitLabel = priceUnitLabel;
        
        
        /**
         充值
         */
        UIButton *rechargeBtn = [[UIButton alloc] init];
        [rechargeBtn setTitle:@"充值"];
        [rechargeBtn setImage:@"carddetail_icon_recharge"];
        [rechargeBtn setTitleColor:CSColorFromRGB(0x0a0a0a)];
        rechargeBtn.titleLabel.font = MidFont;
        [self addSubview:rechargeBtn];
        self.rechargeBtn = rechargeBtn;
        
        /**
         扣费
         */
        UIButton *chargeBtn = [[UIButton alloc] init];        
        chargeBtn.titleLabel.font = MidFont;
        [chargeBtn setTitle:@"扣费"];
        [chargeBtn setImage:@"carddetail_icon_reduce"];
        [chargeBtn setTitleColor:CSColorFromRGB(0x0a0a0a)];
        [self addSubview:chargeBtn];
        self.chargeBtn = chargeBtn;
        
        /**
         请假
         */
        UIButton *leaveBtn = [[UIButton alloc] init];
        leaveBtn.titleLabel.font = MidFont;
        [leaveBtn setTitle:@"请假"];
        [leaveBtn setImage:@"carddetail_icon_rest"];
        [leaveBtn setTitleColor:CSColorFromRGB(0x0a0a0a)];
        [self addSubview:leaveBtn];
        self.leaveBtn = leaveBtn;
        
        [self setConstraints];
    }
    
    return self;
}

-(void)setConstraints{
    
    /**
     背景
     */
    [self.backgroundImageView mas_remakeConstraints:^(MASConstraintMaker *make) {
       
        make.top.left.width.mas_equalTo(self);
        
    }];
    
    
    /**
     卡背景
     */
    [self.bgView mas_remakeConstraints:^(MASConstraintMaker *make) {
       
        make.left.width.mas_equalTo(self);
        
        make.bottom.mas_equalTo(self.backgroundImageView);
        
    }];
    
    /**
     卡名称
     */
    [self.cardNameLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
        
        make.top.mas_equalTo(self.bgView).offset(40);
        
        make.left.mas_equalTo(self.bgView).offset(35);
    }];
    
    /**
     会员卡ID
     */
    [self.cardIdLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
        
        make.right.mas_equalTo(self.bgView).offset(-35);
        
        make.centerY.mas_equalTo(self.cardNameLabel);
    }];
    
    /**
     线条
     */
    [self.lineView mas_remakeConstraints:^(MASConstraintMaker *make) {
        
        make.left.mas_equalTo(self.cardNameLabel);
        
        make.top.mas_equalTo(self.cardNameLabel.mas_bottom).offset(15);
        
        make.height.mas_equalTo(3);
        
        make.width.mas_equalTo(40);
    }];

    /**
     有效期
     */
    [self.validLabel mas_remakeConstraints:^(MASConstraintMaker *make) {

        make.left.mas_equalTo(self.validTimeLabel);

        make.bottom.mas_equalTo(self.validTimeLabel.mas_top).offset(-10);
    }];

    /**
     有效期
     */
    [self.validTimeLabel mas_remakeConstraints:^(MASConstraintMaker *make) {

        make.left.mas_equalTo(self.cardNameLabel);

        make.bottom.mas_equalTo(self.bgView).offset(-22);
    }];

    /**
     价格
     */
    [self.priceLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
       
        make.right.mas_equalTo(self.priceUnitLabel.mas_left);
        
        make.bottom.mas_equalTo(self.priceUnitLabel).offset(4);
    }];
    
    /**
     元
     */
    [self.priceUnitLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
       
        make.right.mas_equalTo(self.cardIdLabel);
        
        make.bottom.mas_equalTo(self.validTimeLabel);
    }];
    
    
    //CGFloat width = SCREEN_WIDTH / 4;
    
    /**
     充值
     */
    [self.rechargeBtn mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.bgView.mas_bottom).offset(20);
        make.left.mas_equalTo(self.bgView).offset(20);
        make.height.mas_equalTo(60);
        make.bottom.mas_equalTo(self).offset(-20);
    }];

    /**
     扣费
     */
    [self.chargeBtn mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.rechargeBtn);
        make.left.mas_equalTo(self.rechargeBtn.mas_right);
        make.width.height.mas_equalTo(self.rechargeBtn);
    }];

    /**
     请假
     */
    [self.leaveBtn mas_remakeConstraints:^(MASConstraintMaker *make) {

        make.top.mas_equalTo(self.rechargeBtn);
        make.left.mas_equalTo(self.chargeBtn.mas_right);
        make.width.height.mas_equalTo(self.rechargeBtn);
        make.right.mas_equalTo(self.bgView).offset(-20);
    }];
    
}

-(void)layoutSubviews{
    
    /**
     充值
     */
    [self.rechargeBtn titleBelowTheImageWithSpace:10];
    
    /**
     扣费
     */
    [self.chargeBtn titleBelowTheImageWithSpace:10];
    
    /**
     请假
     */
    [self.leaveBtn titleBelowTheImageWithSpace:10];
    
}

-(void)setSelectRow:(NSInteger)selectRow{
    
    self.bgView.image = [UIImage imageNamed:self.bgNameArray[selectRow % 3]];
    
    //黑色
    if (selectRow % 3 == 0) {
        
        self.cardNameLabel.textColor = CSColorFromRGB(0xffffff);
        
        /**
         线条
         */
        self.lineView.backgroundColor = CSColorFromRGB(0x403f4a);
        
        /**
         会员卡ID
         */
        self.cardIdLabel.textColor = CSColorFromRGB(0x686578);
        
        
        /**
         y有效期
         */
        self.validLabel.textColor = CSColorFromRGB(0x686578);
        
        /**
         时间
         */
        self.validTimeLabel.textColor = CSColorFromRGB(0xffffff);
        
    }
    else{
        
        self.cardNameLabel.textColor = CSColorFromRGB(0x0a0a0a);
        
        /**
         线条
         */
        self.lineView.backgroundColor = CSColorFromRGB(0xeccc08);
        
        /**
         会员卡ID
         */
        self.cardIdLabel.textColor = CSColorFromRGB(0xb1980d);
        
        
        /**
         y有效期
         */
        self.validLabel.textColor = CSColorFromRGB(0xb1980d);
        
        /**
         时间
         */
        self.validTimeLabel.textColor = CSColorFromRGB(0x0a0a0a);
    }
}

@end
